package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.DepartmentDao;
import ysq.xyg.model.Department;
import ysq.xyg.service.DepartmentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分销级别
 *
 * @author congcong tao
 * @date 2018/11/27 14:20
 */
@Service("departmentService")
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService {

    @Resource
    private DepartmentDao departmentDao;
    @Autowired
    public void setDepartmentDao(DepartmentDao departmentDao) {
        this.baseDao = departmentDao;
    }

    @Override
    public PageInfo<Department> pageInfo(Department department, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(Department.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(department.getName())) {
            criteria.andLike("name", "%" + department.getName() + "%");
        }
        List<Department> list = departmentDao.selectByExample(example);
        return new PageInfo<Department>(list);
    }
    @Override
    public List<Department> list(Department department) {
        // 通用Example查询
        Example example = new Example(Department.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(department.getName())) {
            criteria.andLike("name", "%" + department.getName() + "%");
        }
        List<Department> list = departmentDao.selectByExample(example);
        return list;
    }
}
